<?php

namespace App\Models;

use App\Services\GoodService;
use Dcat\Admin\Models\Administrator;
use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

/**
 * App\Models\Good
 *
 * @property \App\Models\Category|null $category
 * @property \App\Models\UserCollect|null $collect
 * @method static Builder|Good newModelQuery()
 * @method static Builder|Good newQuery()
 * @method static Builder|Good query()
 * @mixin \Eloquent
 * @property int $id
 * @property string $name 商品名称
 * @property int $category_id 商品分类
 * @property string|null $image 商品列表图
 * @property array|null $images 商品轮播图
 * @property string|null $content 商品详情
 * @property string $price 商品售价
 * @property int $sort 商品排序
 * @property int $status 状态:0=上架,1=下架
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static Builder|Good whereId($value)
 * @property-read \App\Models\OrderDetail|null $sales
 * @method static Builder|Good whereAdminId($value)
 * @method static Builder|Good whereCate($value)
 * @method static Builder|Good whereCollected($value)
 * @method static Builder|Good whereState($value)
 * @property float $city_rate0 无区代理的市代理分成比例
 * @property float $city_rate1 有区代理的市代理分成比例
 * @property float $district_rate 区代理的分成比例
 * @property float $shop_rate 门店分成比例
 * @property float $user_rate 上级用户分销比例
 * @property array $level_ids
 * @method static Builder|Good whereCategoryId($value)
 * @method static Builder|Good whereCityRate0($value)
 * @method static Builder|Good whereCityRate1($value)
 * @method static Builder|Good whereContent($value)
 * @method static Builder|Good whereCreatedAt($value)
 * @method static Builder|Good whereDistrictRate($value)
 * @method static Builder|Good whereImage($value)
 * @method static Builder|Good whereImages($value)
 * @method static Builder|Good whereName($value)
 * @method static Builder|Good wherePrice($value)
 * @method static Builder|Good whereShopRate($value)
 * @method static Builder|Good whereStatus($value)
 * @method static Builder|Good whereUpdatedAt($value)
 */
class Good extends Model
{
	use HasDateTimeFormatter;

    protected $casts = ['images'=>'json','sku'=>'json','level_ids'=>AutoImplodeExplode::class,'levels'=>'json'];

    protected static function booted()
    {
    }

    public function collect(){
        return $this->belongsTo(UserCollect::class,"id","good_id");
    }

    public function category(){
        return $this->hasOne(Category::class,"id","category_id")->select(['id','name']);
    }


    public function sales(){
        return $this->belongsTo(OrderDetail::class,"id","good_id");
    }

}
